//
//  OMG_CollectionViewController.m
//  A_project2.0
//
//  Created by Tiny on 16/3/15.
//  Copyright © 2016年 七平. All rights reserved.
//

#import "OMG_CollectionViewController.h"

@interface OMG_CollectionViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) NSMutableArray *dataArr;
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation OMG_CollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatTableView];
    [self dataHandler];
}
- (void)viewDidAppear:(BOOL)animated
{
    if (_dataArr.count == 0) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示信息" message:@"当前收藏为空" preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alert animated:YES completion:nil];
        [self performSelector:@selector(diss) withObject:self afterDelay:1];
    }
}
- (void)diss
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
- (void)dataHandler
{
    // 解档
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject stringByAppendingPathComponent:@"collectionWebView.txt"];
    self.dataArr = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
}
- (void)creatTableView
{
    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.textLabel.text = [_dataArr[indexPath.row] title];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
